unit FPresupuestosEditFotocomp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Mask, DBCtrls, DB, ADODB, Grids,
  XDBGrids, ZAbstractRODataset, ZDataset;

type
  TFormPresupuestosEditFotoComp = class(TForm)
    Label1: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    BtnAceptar: TSpeedButton;
    BtnCancelar: TSpeedButton;
    dsFoto: TDataSource;
    Label6: TLabel;
    GridFoto: TXDBGrid;
    Label2: TLabel;
    eColores: TEdit;
    eTotal: TEdit;
    Label3: TLabel;
    qFoto: TZReadOnlyQuery;
    procedure BtnAceptarClick(Sender: TObject);
    procedure BtnCancelarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure dsFotoDataChange(Sender: TObject; Field: TField);
    procedure GridFotoPaintColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TXColumn; Highlight: Boolean;
      Selections: TSelections; var Color: TColor; Font: TFont;
      var Image: TPersistent);
  private
    { Private declarations }
  public
    { Public declarations }
    numColores: Integer;
  end;

var
  FormPresupuestosEditFotoComp: TFormPresupuestosEditFotoComp;

implementation

uses
  ModDatos;

{$R *.dfm}

procedure TFormPresupuestosEditFotoComp.BtnAceptarClick(Sender: TObject);
begin
  md.tPresup_Fotocomposicion.Append;
  md.tPresup_Fotocomposicion.FieldByName( 'ID_PRESUP').AsInteger := MD.TPresupuestos.FieldByName( 'ID_PRESUP').AsInteger;
  md.tPresup_Fotocomposicion.FieldByName( 'CONCEPTO').AsString   := qFoto.FieldByName( 'MODELO').AsString;
  md.tPresup_Fotocomposicion.FieldByName( 'TARIFA').AsInteger    := 0;
  md.tPresup_Fotocomposicion.FieldByName( 'PRECIO').AsFloat      := qFoto.FieldByName( 'TARIFA').AsFloat;
  md.tPresup_Fotocomposicion.FieldByName( 'COLORES').AsInteger   := numColores;
  md.tPresup_Fotocomposicion.FieldByName( 'COSTE_COLOR').AsFloat := qFoto.FieldByName( 'TARIFA_COLOR').AsFloat;
  md.tPresup_Fotocomposicion.FieldByName( 'TOTAL').AsFloat       := qFoto.FieldByName( 'TARIFA').AsFloat +
                                                                    qFoto.FieldByName( 'TARIFA_COLOR').AsFloat * numColores;
  md.tPresup_Fotocomposicion.Post;
  modalResult := mrOk;
  qFoto.Close;
  Close;
end;

procedure TFormPresupuestosEditFotoComp.BtnCancelarClick(Sender: TObject);
begin
  modalResult := mrCancel;
  qFoto.Close;
  Close;
end;

procedure TFormPresupuestosEditFotoComp.FormShow(Sender: TObject);
var
  StrSQL : String;
begin
  eColores.Text := IntToStr( numColores);
  //StrSQL := 'SELECT MODELO, ANCHO, ALTO, ' + cmpTarifa + ' TARIFA, ' + cmpTarifa + '_COLOR TARIFA_COLOR ' +
  StrSQL := 'SELECT MODELO, ANCHO, ALTO, TARIFA, TARIFA_COLOR ' +
            'FROM TARIFAS_FOTOCOMPOSICION ' +
            'ORDER BY MODELO, ALTO, ANCHO ';
  md.AbreQuery( qFoto, StrSQL);
end;

procedure TFormPresupuestosEditFotoComp.dsFotoDataChange(Sender: TObject;
  Field: TField);
begin
  eTotal.Text := FormatFloat( '#,##0.00', qFoto.FieldByName( 'TARIFA').AsFloat +
                                          qFoto.FieldByName( 'TARIFA_COLOR').AsFloat * numColores);
end;

procedure TFormPresupuestosEditFotoComp.GridFotoPaintColumnCell(
  Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TXColumn;
  Highlight: Boolean; Selections: TSelections; var Color: TColor;
  Font: TFont; var Image: TPersistent);
begin
  if (slCellSelected in Selections) or (slCellFixed in Selections) then Exit
  else
    //Cada Registro le damos un color diferente
    if slMultiSelected in Selections then //Color := $00F08000
      if Odd( TXDBGrid( Sender).DataSource.DataSet.RecNo) then Color := $0AF0047
                                                          else Color := $0FF0000
    else
      //Cada Registro le damos un color diferente
      if Odd( TXDBGrid( Sender).DataSource.DataSet.RecNo) then Color := $0E7FFFF
                                                          else Color := $0C7FFFF
end;

end.
